/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package org.tnmk.worktime.service.filter;

import org.tnmk.common.util.Filter;
import org.joda.time.DateTime;
import org.tnmk.worktime.utils.TimeUtils;

/**
 *
 * @author tnmkhoi
 */
public class RangeTimeFilter implements Filter<DateTime> {
  private final DateTime begin;
  private final DateTime end;

  public RangeTimeFilter(DateTime begin, DateTime end) {
    this.begin = begin;
    this.end = end;
  }

  public RangeTimeFilter(String sBegin, String sEnd, String pattern) {
    this.begin = TimeUtils.toDateTime(sBegin, pattern);
    this.end = TimeUtils.toDateTime(sEnd, pattern);
  }
  
  public boolean accept(DateTime model) {
    boolean rs = false;
    if (model == null) {
      return rs;
    }
    DateTime time = model;
    rs = time.isAfter(begin) && time.isBefore(end);
    return rs;
  }
}
